<?php

class ModelCreator_ZipFile {

    public function __construct($arrPost) {
        echo $this->createZip($arrPost['table'], $arrPost['project']);
    }

    protected function createZip($files, $project) {
        $zip = new ZipArchive();
        $zip_file = time().".zip";
        if ($zip->open("../models/" . $project . DIRECTORY_SEPARATOR . $zip_file, ZipArchive::CREATE) != true) {
            return false;
        }
        foreach ($files as $file) {
            if (file_exists("../models/" . $project . DIRECTORY_SEPARATOR . $file)) {
                $zip->addFile("../models/" . $project . DIRECTORY_SEPARATOR . $file, $file);
            }
        }
        
        $zip->close();
        return "models/" . $project . "/" . $zip_file;
    }

}
